/*
 * Tint Browser for Android
 * 
 * Copyright (C) 2012 - to infinity and beyond J. Devauchelle and contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package com.cnbrowser.android.ui.fragments.homepage;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.cnbrowser.android.R;
import com.cnbrowser.android.ui.cbrowser.StartPageItemClickedListener;

public class RightFragment extends Fragment {
    private static final String TAG = "RightFragment";

    private View thisView = null;
    private StartPageItemClickedListener startPageItemClickedListener;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        thisView = inflater.inflate(R.layout.cb_start_page_right_fragment, container, false);
        if (thisView == null) return null;
        WebView webView= (WebView) thisView.findViewById(R.id.webView);
        webView.getSettings().setJavaScriptEnabled(true);

        webView.setWebViewClient(new WebViewClient(){
            public boolean shouldOverrideUrlLoading (WebView view, String url){
                startPageItemClickedListener.onItemClicked(url);
                return true;
            }
        });


        webView.loadUrl("file:///android_asset/right.htm");
        return thisView;
    }


    public void setStartPageItemClickedListener(StartPageItemClickedListener startPageItemClickedListener) {
        this.startPageItemClickedListener = startPageItemClickedListener;
    }

    public StartPageItemClickedListener getStartPageItemClickedListener() {
        return startPageItemClickedListener;
    }
}
